<template>
  <div class="user-container">
    <el-card class="user-card">
      <template #header>
        <div class="card-header">
          <span>用户管理</span>
          <el-button type="primary" @click="handleAddUser">添加用户</el-button>
        </div>
      </template>
      <el-table :data="users" style="width: 100%">
        <el-table-column prop="id" label="ID" width="50" />
        <el-table-column prop="name" label="用户名" />
        <el-table-column prop="email" label="邮箱" />
        <el-table-column prop="role" label="角色" />
        <el-table-column label="操作" width="150">
          <template #default="scope">
            <el-button size="mini" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessageBox, ElMessage } from 'element-plus'

const users = ref([
  { id: 1, name: '张三', email: 'zhangsan@example.com', role: '管理员' },
  { id: 2, name: '李四', email: 'lisi@example.com', role: '用户' },
  { id: 3, name: '王五', email: 'wangwu@example.com', role: '用户' }
])

const handleAddUser = () => {
  // 添加用户逻辑
  ElMessage.success('添加用户功能待实现')
}

const handleEdit = (user) => {
  // 编辑用户逻辑
  ElMessage.success(`编辑用户 ${user.name} 功能待实现`)
}

const handleDelete = (user) => {
  ElMessageBox.confirm(`确定要删除用户 ${user.name} 吗？`, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    // 删除用户逻辑
    ElMessage.success(`用户 ${user.name} 已删除`)
  }).catch(() => {
    ElMessage.info('已取消删除')
  })
}
</script>

<style scoped lang="scss">
.user-container {
  padding: 20px;
}

.user-card {
  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;

    span {
      font-size: 18px;
      font-weight: bold;
    }
  }
}
</style> 